<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use    \think\facade\Route;

Route::group('yj', function () {
    //用户的资源路由
//    Route::resource('user', \app\yj\controller\UserController::class);
    Route::get('user', 'yj/UserController/index');
    Route::post('user', 'yj/UserController/save');
    Route::put('user', 'yj/UserController/update');
    Route::delete('user', 'yj/UserController/delete');
    Route::post('finduser', 'yj/UserController/findUser');
    Route::post('userdw', 'yj/UserController/userdw');


    //通知
    Route::any('notice', 'yj/NoticeController/index');
    //增加浏览量
    Route::post('userseenotice', 'yj/NoticeController/userseenotic');


    //修改个人信息
    Route::put('edituserinfo', 'yj/UserController/editInfo');


    //区域级别的资源路由
    Route::get('qy', 'yj/QuyuController/index');
    Route::post('qy', 'yj/QuyuController/save');
    Route::put('qy', 'yj/QuyuController/update');
    Route::delete('qy', 'yj/QuyuController/delete');

    //数据类型
    Route::resource('datatype', \app\yj\controller\DataTypeController::class);

    //数据管理
//    Route::get('data', 'yj/DataController/index');
    Route::post('data', 'yj/DataController/save');
    Route::put('data', 'yj/DataController/update');
    Route::delete('data', 'yj/DataController/delete');
    //获取指定时间的事件
    Route::post('gettimedata', 'yj/DataController/getTimeCount');
    //解决了事件
    Route::post('solvedata', 'yj/DataController/solveData');


    //获取最新的数据
    Route::post('getnewdata', 'yj/DataController/getNewData');


    //数据管理

    Route::put('failePoint', 'yj/FailepController/update');
    Route::delete('failePoint', 'yj/FailepController/delete');
    //文件管理
    Route::post('file', 'yj/FileController/save');
    Route::put('file', 'yj/FileController/update');
    Route::delete('file', 'yj/FileController/delete');

    //菜单管理

    Route::post('menu', 'yj/MenuController/save');
    Route::put('menu', 'yj/MenuController/update');
    Route::delete('menu', 'yj/MenuController/delete');

    //权限管理
//    Route::resource('rule', \app\yj\controller\RuleController::class);
    Route::get('rule', 'yj/RuleController/index');
    Route::post('rule', 'yj/RuleController/save');
    Route::put('rule', 'yj/RuleController/update');
    Route::delete('rule', 'yj/RuleController/delete');

    //角色管理
//    Route::resource('role', \app\yj\controller\RoleController::class);
    Route::get('role', 'yj/RoleController/index');
    Route::post('role', 'yj/RoleController/save');
    Route::put('role', 'yj/RoleController/update');
    Route::delete('role', 'yj/RoleController/delete');

    //地图列表
    Route::post('maps', 'yj/MapsController/save');
    Route::put('maps', 'yj/MapsController/update');
    Route::delete('maps', 'yj/MapsController/delete');

    //批量删除data
    Route::post('/delalldata', "yj/DataController/delAllData");


    //数据参数
    Route::post('dataconfig', 'yj/DataConfigController/save');
    Route::put('dataconfig', 'yj/DataConfigController/update');
    Route::delete('dataconfig', 'yj/DataConfigController/delete');

});
//->middleware(\app\yj\middleware\UserAuth::class);

Route::post('yj/login', 'yj/LoginController/login');


//不需要权限验证的

Route::group('yj', function () {
    Route::post('failePoint', 'yj/FailepController/save');

    Route::get('mapconfig', 'yj/MapConfigController/index');
    Route::put('mapconfig', 'yj/MapConfigController/update');


    Route::get('failePoint', 'yj/FailepController/index');
    Route::get('data', 'yj/DataController/index');
    //图标列表
    Route::resource('icon', \app\yj\controller\IconController::class);
    //文件列表
    Route::get('file', 'yj/FileController/index');
    //地图参数列表
    Route::get('dataconfig', "yj/DataConfigController/index");
    //地图列表
    Route::get('maps', 'yj/MapsController/index');
    //菜单列表
    Route::get('menu', 'yj/MenuController/index');

    //上传数据
    Route::post('uploaduserfile', 'yj/DataController/uploaduserfile');


    //故障点icon

    Route::any('failepointicon', function (\think\Request $request) {
        $method = $request->method();
        $method = strtolower($method);

        if ($method == 'get') {
            $fpicon = \app\yj\model\fpiconModel::find(1);
            $icon = \app\yj\model\IconModel::find($fpicon->iconid);
            return json(['code' => 200, 'data' => $icon]);
        }

//        if ($method == 'post') {
//
//        }
        if ($method == 'put') {
            $iconid = $request->put('iconid');
            $fpicons = \app\yj\model\fpiconModel::find(1);
            $fpicons->iconid = $iconid;
            $fpicons->save();
            $icon = \app\yj\model\IconModel::find($iconid);
            return json(['code' => 200, 'data' => $icon]);
        }
        if ($method == 'delete') {

        }
    });

});
//    ->header('Access-Control-Allow-Origin', '*')
//    ->header("Access-Control-Allow-Headers", "Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With,token")
//    ->allowCrossDomain();
Route::any('/yj/getfailepoint', function (\think\Request $request) {

    $time = $request->request('time');
    $time2 = $time - 5;
    $data = \app\yj\model\FailepModel::where('create_time', '<=', $time)
        ->where('create_time', ">=", $time2)->select();
    foreach ($data as $v) {
        $v['gd'] = '';
        if ($v->gdid != '') $v['gd'] = \app\yj\model\DataModel::where('gdid', $v->gdid)->find();
    }
    return json([code => 200, 'data' => $data]);
});

Route::get('/yj/getfailepoints', function (\think\Request $request) {
    $pid = $request->get('id');
    $data = \app\yj\model\FailepModel::find($pid);
    $data['gd'] = '';
    if ($data->gdid != '') $data['gd'] = \app\yj\model\DataModel::where('gdid', $data->gdid)->find();

    return json_encode(['code' => 200, 'data' => $data]);
});

Route::get('yj/failepbyuser', function (\think\Request $request) {
    $id = $request->get('id');
    if ($id != '') {
        $faileps = \app\yj\model\FailepModel::where('uid', $id)->select()->toArray();
        foreach ($faileps as $v) {
            if ($v['gdid'] != '') $v['gd'] = \app\yj\model\DataModel::where('gdid', $v['gdid'])->find();
        }
        return json_encode(['code' => 200, 'data' => $faileps]);
    }
});


